package com.gitee.melin.bee.core.jdbc.relational;

import com.gitee.melin.bee.core.jdbc.enums.DataSourceType;
import lombok.Builder;
import lombok.Getter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.Map;

@Getter
@Builder(builderClassName = "Builder", setterPrefix = "with")
public class ConnectionInfo {

    private DataSourceType dataSourceType;

    private String username;

    private String password;

    private String jdbcUrl;

    private String databaseName;

    private String principal;

    private String keytabFile;

    private String krb5File;

    @lombok.Builder.Default
    private Integer minimumIdle = 1;

    @lombok.Builder.Default
    private Integer maxPoolSize = 100;

    private Map<String, String> properties;

    private Integer queryTimeout; //seconds

    private String compatibleMode;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        ConnectionInfo that = (ConnectionInfo) o;

        return new EqualsBuilder().append(dataSourceType, that.dataSourceType)
                .append(jdbcUrl, that.jdbcUrl).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(dataSourceType).append(jdbcUrl).toHashCode();
    }

    @Override
    public String toString() {
        return "DataConnector{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", jdbcUrl='" + jdbcUrl + '\'' +
                ", properties=" + properties +
                '}';
    }
}
